import 'package:flame/game.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class PauseMenu extends StatelessWidget {
  PauseMenu({Key? key, required this.game}) : super(key: key);
  static const String menuId = 'PauseMenu';
  final Game game;
  final TextStyle shadowStyle = const TextStyle(
      fontSize: 24, shadows: [Shadow(color: Colors.white, blurRadius: 10)]);
  @override
  Widget build(BuildContext context) {
    return Material(
      color: Colors.transparent,
      child: Center(
        child: Container(
          color: Colors.black26,
          alignment: Alignment.center,
          padding: const EdgeInsets.symmetric(vertical: 20),
          child: Wrap(
            spacing: 30,
            direction: Axis.vertical,
            crossAxisAlignment: WrapCrossAlignment.center,
            children: [
              Text(
                '游戏暂停',
                style: shadowStyle,
              ),
              ElevatedButton(onPressed: _continue, child: const Text('继续游戏')),
              ElevatedButton(
                  onPressed: () => Get.back(), child: const Text('退出游戏'))
            ],
          ),
        ),
      ),
    );
  }

  void _continue() {
    game.resumeEngine();
    game.overlays.remove(menuId);
  }
}
